package com.fattyCorps.config.gameConfig;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.fattyCorps.mapper.GlobalMouldMapper;
import com.fattyCorps.obj.mould.GlobalMould;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.List;

@Component
public class GlobalConfig implements CommandLineRunner {

    private HashMap<String, String> globalConfigMap = new HashMap<>();

    public static final String STAR_LV = "star_lv";
    public static final String MAX_STAR = "max_star";

    public static final String PLAYER_INIT_HEAD = "player_init_head";
    public static final String PLAYER_INIT_LV = "player_init_lv";
    public static final String PLAYER_INIT_COIN = "player_init_coin";
    public static final String PLAYER_INIT_GUANQIA = "player_init_guanqia";

    public static final String PLAYER_INIT_ITEMS = "player_init_items";

    public static final String FREE_COLL_TIME = "free_roll_time";
    public static final String ONE_ROLL_COIN = "one_roll_coin";
    public static final String TEN_ROLLS_COIN = "ten_rolls_coin";

    public static final String ONE_HERO_NEED_FRAGMENT_NUM = "60";



    @Autowired
    GlobalMouldMapper globalMouldMapper;

    public String getStringValue(String name){
        return globalConfigMap.get(name);
    }

    public Integer getIntValue(String name){
        return Integer.valueOf(globalConfigMap.get(name));
    }

    @Override
    public void run(String... args) throws Exception {
        QueryWrapper<GlobalMould> wrapper = new QueryWrapper<>();
        List<GlobalMould> globalMoulds = globalMouldMapper.selectList(wrapper);
        for (int i = 0; i < globalMoulds.size(); i++) {
            GlobalMould globalMould = globalMoulds.get(i);
            globalConfigMap.put(globalMould.getName(), globalMould.getValue());
        }
    }
}
